import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaRightMenu, WeaTable } from 'ecCom';
import { Spin } from 'antd';
import ScoreSettingOperation from "./ScoreSettingOperation";

/**
 * 考核设置-分数段设置
 * jiansong 2019/6/18
 */
@inject("scoreSettingStore")
@observer
export default class ScoreSetting extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.scoreSettingStore;
    }

    componentWillMount() {
        this.store.getTableDatas();
    }

    render() {
        const { menu } = this.props;
        const { data, selectedRowKeys, canedit, loading, symbolValue, initEditForm } = this.store;
        const columns = [
            {
                title: '分段名称', dataIndex: 'gardename',
                render: (text, data) => {
                    return canedit ? <a href="javascript:void(0);" onClick={() => initEditForm(data)}>{text}</a> : text
                }
            },
            {
                title: '开始值符号', dataIndex: 'beginSymbol',
                render: text => <span>{symbolValue[text - 1]}</span>,
            },
            { title: '开始值', dataIndex: 'beginscore' },
            {
                title: '结束值符号', dataIndex: 'endSymbol',
                render: text => <span>{symbolValue[text - 1]}</span>,
            },
            { title: '结束值', dataIndex: 'endscore' },
            { title: '显示顺序', dataIndex: 'rank' }
        ];
        return (
            <Spin spinning={loading}>
                <div style={{ height: '100vh' }}>
                    <WeaRightMenu datas={menu} showUrlItem={false}>
                        <WeaTable
                            rowKey="id"
                            columns={columns}
                            dataSource={data}
                            scroll={{ y:window.innerHeight-200 }}
                            pagination={{
                                total: data.length
                            }}
                            rowSelection={canedit ? {
                                selectedRowKeys,
                                onChange: this.onSelectChange,
                            } : false}
                        />
                        <ScoreSettingOperation />
                    </WeaRightMenu>
                </div>
            </Spin>
        )
    }

    //多选框值变化
    onSelectChange = (selectedRowKeys, selectedRows) => {
        this.store.selectedRowKeys = selectedRowKeys
    };

}
